using System;
using System.IO;
using System.Windows.Input;
using ScriptEase.Shell.Properties;



namespace ScriptEase.Shell.Commands
{
    internal class EditStaticMappingXmlCommand : ICommand
    {
        private readonly ShellViewModel _viewViewModel;



        public EditStaticMappingXmlCommand(ShellViewModel viewViewModel)
        {
            _viewViewModel = viewViewModel;
        }



        public void Execute(object parameter)
        {
            string editor = Settings.Default.Editor;
            if (!File.Exists(editor)) editor = "Notepad.exe";

            PublicFunc.RunProcess(editor, "\"" + _viewViewModel.Project.StaticMappingFilePath + "\"");
        }



        public bool CanExecute(object parameter)
        {
            return _viewViewModel.Project!=null && !String.IsNullOrEmpty(_viewViewModel.Project.StaticMappingFilePath) &&
                   (_viewViewModel.ProjectLoadStatus == ProjectStatus.Connected || _viewViewModel.ProjectLoadStatus == ProjectStatus.LoadedDisconnected);
        }



        public event EventHandler CanExecuteChanged;
    }
}